// pages/searchList/searchList.js
Page({

  /**
   * 页面的初始数据
   * "111","123","65465465","546"
   */
  data: {
    showList:[],
    searchValue:"",
    dataNone:false,
    good_type:null,
  },
  search:function(){
    this.showList = [];
    let that = this;
    this.setData({
      searchValue:this.searchValue
    })
    console.log(this.searchValue);
    wx.request({
      url: 'http://api_devs.wanxikeji.cn/api/goodList',
      method:'POST',
      data:{
        page:"1",
        size:"100",
        search:this.searchValue
      },success:function(res){
         that.showList = res.data.data.data;
         if(that.showList.length == 0){
          that.dataNone = true;
        }else{
          that.dataNone = false;
        }

        that.setData({
          showList:that.showList,
          dataNone:that.dataNone
        })
      }
    })

  },
  inputChange:function(value){
    this.searchValue = value.detail.value;
  },
  goods:function(e){
    let index = e.currentTarget.dataset.index;
    console.log(this.data.showList[index].good_id);
    wx.navigateTo({
      url: '../commodity/commodity?indexArr='+ this.data.showList[index].good_id
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.searchValue = options.searchValue;
    this.good_type = options.good_type;
    this.setData({
      searchValue:options.searchValue
    })
    console.log(this.searchValue);
    let that = this;
    wx.request({
      url: 'http://api_devs.wanxikeji.cn/api/goodList',
      method:'POST',
      data:{
        page:"1",
        size:"100",
        good_type:this.good_type,
        search:this.searchValue
      },success:function(res){
        console.log(res);
         that.showList = res.data.data.data;

         if(that.showList.length == 0){
           that.dataNone = true;
         }else{
           that.dataNone = false;
         }
         that.setData({
          showList:that.showList,
          dataNone:that.dataNone
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})